extends Node2D

var type = 0 # 攻击类型， 直射、散花、激光、炸弹
var is_enemy = false # 是否是敌人发出
var init_pos # 初始位置

var polar_num = 5


# Called when the node enters the scene tree for the first time.
func _ready():
	#print("attack ready")
	
	match type:
		0: #直线射击
			var bullet = preload("res://scene/object/bullet.tscn").instantiate()
			bullet.position = init_pos
			
			if is_enemy == true:
				bullet.collision_mask = 1
				bullet.angle = 180
			else:
				bullet.collision_mask = 2	
				bullet.angle = 0
			add_child(bullet)	
			
		1: # 散花弹	
			for i in range(1, polar_num+1):
				var bullet = preload("res://scene/object/bullet.tscn").instantiate()
				bullet.position = init_pos
				var angle
				
				if is_enemy == true:
					bullet.collision_mask = 1
					angle = 90 + i * 180/( polar_num + 1)
				else:
					bullet.collision_mask = 2	
					angle = -90 + i * 180/( polar_num + 1)
					
				#print(angle)
				bullet.angle = angle	
					
				#print("bullet.collision_layer"+str(bullet.collision_mask))	
				add_child(bullet)
			

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if get_child_count() ==0 :
		queue_free()
